// 数据库连接配置
const { Sequelize } = require('sequelize');


// 初始化 Sequelize 实例
const sequelize = new Sequelize(
  process.env.DB_NAME,
  process.env.DB_USER, 
  process.env.DB_PASSWORD, {
  host: process.env.DB_HOST,
  dialect: 'mysql', // 或者其他数据库方言，如 'postgres', 'sqlite', 'mssql'
  // 其他配置选项...
});


// 测试数据库连接
sequelize.authenticate()
  .then(() => {
    console.log('Database connection has been established successfully.');
    console.log('----数据库连接成功----');
  })
  .catch(err => {
    console.error('Unable to connect to the database:', err);
  });

// 将 sequelize 实例设置为全局变量
// global.sequelize = sequelize;

module.exports = sequelize;





// const mysql = require('mysql2');

// const pool = mysql.createPool({
//   host: process.env.DB_HOST,
//   port: process.env.DB_PORT,
//   user: process.env.DB_USER,
//   password: process.env.DB_PASSWORD,
//   database: process.env.DB_NAME,
//   waitForConnections: true,
//   connectionLimit: 10,
//   queueLimit: 0
// });

// module.exports = pool.promise();